<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>个人资料 - 测盟汇系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        :root {
            --primary-color: #2c5545;
            --primary-light: #3a7d62;
            --primary-hover: #1e4636;
            --accent-color: #8ba888;
            --error-color: #d64541;
            --success-color: #3a7d62;
            --text-color: #333;
            --text-light: #555;
            --border-color: #d1d9d6;
            --bg-light: #f5f7f6;
            --bg-page: #e8ecea;
            --white: #fff;
            --shadow: 0 4px 24px rgba(44, 85, 69, 0.1);
            --radius: 12px;
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: var(--text-color);
            line-height: 1.6;
            background-color: var(--bg-page);
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 250px;
            background: var(--primary-color);
            color: var(--white);
            padding: 1.5rem 0;
            height: 100vh;
            position: fixed;
            transition: var(--transition);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 1.5rem 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar-header h3 {
            display: flex;
            align-items: center;
            font-weight: 600;
        }

        .sidebar-header h3 i {
            margin-right: 0.5rem;
            font-size: 1.2rem;
        }

        .sidebar-menu {
            padding: 1rem 0;
        }

        .menu-title {
            padding: 0.5rem 1.5rem;
            font-size: 0.8rem;
            text-transform: uppercase;
            color: rgba(255, 255, 255, 0.5);
            letter-spacing: 1px;
        }

        .menu-item {
            padding: 0.75rem 1.5rem;
            display: flex;
            align-items: center;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: var(--transition);
        }

        .menu-item i {
            margin-right: 0.8rem;
            width: 20px;
            text-align: center;
        }

        .menu-item:hover {
            background: rgba(255, 255, 255, 0.1);
            color: var(--white);
        }

        .menu-item.active {
            background: var(--primary-hover);
            color: var(--white);
            border-left: 3px solid var(--accent-color);
        }

        /* 主内容区域 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 2rem;
            transition: var(--transition);
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 1px solid var(--border-color);
        }

        .header h1 {
            color: var(--primary-color);
            font-size: 1.8rem;
        }

        .user-profile {
            display: flex;
            align-items: center;
        }

        .user-profile img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 0.8rem;
            object-fit: cover;
        }

        .user-info {
            display: flex;
            flex-direction: column;
        }

        .user-name {
            font-weight: 500;
        }

        .user-role {
            font-size: 0.8rem;
            color: var(--text-light);
        }

        /* 个人资料卡片 */
        .profile-card {
            background: var(--white);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 2rem;
            margin-bottom: 2rem;
            border: 1px solid var(--border-color);
        }

        .profile-header {
            display: flex;
            align-items: center;
            margin-bottom: 2rem;
        }

        .profile-avatar {
            position: relative;
            margin-right: 2rem;
        }

        .profile-avatar img {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            border: 5px solid var(--bg-light);
        }

        .profile-avatar-edit {
            position: absolute;
            bottom: 10px;
            right: 10px;
            width: 36px;
            height: 36px;
            background: var(--primary-color);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--white);
            cursor: pointer;
            transition: var(--transition);
        }

        .profile-avatar-edit:hover {
            background: var(--primary-hover);
            transform: scale(1.1);
        }

        .profile-title h2 {
            color: var(--primary-color);
            margin-bottom: 0.5rem;
        }

        .profile-title p {
            color: var(--text-light);
        }

        /* 信息表格 */
        .profile-form {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 1.5rem;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: var(--primary-color);
            font-weight: 500;
        }

        .form-control {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            font-size: 1rem;
            background: var(--white);
            transition: var(--transition);
            color: var(--text-color);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 2px rgba(44, 85, 69, 0.2);
        }

        select.form-control {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232c5545' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 0.8rem center;
            background-size: 1rem;
            padding-right: 2.5rem;
        }

        .readonly-field {
            background: var(--bg-light);
            cursor: not-allowed;
        }

        /* 按钮区域 */
        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 1rem;
            margin-top: 2rem;
            padding-top: 2rem;
            border-top: 1px solid var(--border-color);
        }

        .btn {
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 6px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }

        .btn-primary {
            background: var(--primary-color);
            color: var(--white);
        }

        .btn-primary:hover {
            background: var(--primary-hover);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid var(--border-color);
            color: var(--text-color);
        }

        .btn-outline:hover {
            background: var(--bg-light);
        }

        .btn i {
            margin-right: 0.5rem;
        }

        /* 错误提示 */
        .error-message {
            color: var(--error-color);
            font-size: 0.9rem;
            margin-top: 0.5rem;
            display: flex;
            align-items: center;
        }

        .error-message i {
            margin-right: 0.5rem;
        }

        /* 成功提示 */
        .success-message {
            color: var(--success-color);
            font-size: 0.9rem;
            margin-top: 0.5rem;
            display: flex;
            align-items: center;
        }

        .success-message i {
            margin-right: 0.5rem;
        }

        /* 密码修改区域 */
        .password-section {
            background: rgba(44, 85, 69, 0.05);
            padding: 1.5rem;
            border-radius: var(--radius);
            margin-top: 2rem;
        }

        .password-title {
            display: flex;
            align-items: center;
            margin-bottom: 1rem;
            color: var(--primary-color);
        }

        .password-title i {
            margin-right: 0.5rem;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
                overflow: hidden;
            }

            .sidebar-header h3 span,
            .menu-title,
            .menu-item span {
                display: none;
            }

            .menu-item {
                justify-content: center;
                padding: 0.75rem 0;
            }

            .menu-item i {
                margin-right: 0;
                font-size: 1.2rem;
            }

            .main-content {
                margin-left: 70px;
            }

            .profile-header {
                flex-direction: column;
                text-align: center;
            }

            .profile-avatar {
                margin-right: 0;
                margin-bottom: 1.5rem;
            }
        }

        @media (max-width: 768px) {
            .main-content {
                padding: 1.5rem;
            }

            .profile-form {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <h3><i class="fas fa-store"></i> <span>测盟汇系统</span></h3>
    </div>

    <div class="sidebar-menu">
        <div class="menu-title">核心功能</div>
        <a href="/index" class="menu-item">
            <i class="fas fa-tachometer-alt"></i>
            <span>控制面板</span>
        </a>

        <div class="menu-title">功能模块</div>
        <a href="#" class="menu-item">
            <i class="fas fa-book-open"></i>
            <span>课程</span>
        </a>
        <a href="/dynamic_list" class="menu-item">
            <i class="fas fa-bullhorn"></i>
            <span>动态</span>
        </a>
        <a href="#" class="menu-item">
            <i class="fas fa-video"></i>
            <span>会议</span>
        </a>

        <div class="menu-title">系统设置</div>
        <a href="/user/profile" class="menu-item active">
            <i class="fas fa-user-cog"></i>
            <span>个人资料</span>
        </a>
        <a href="/enterprise/profile" class="menu-item">
            <i class="fas fa-building"></i>
            <span>企业资料修改</span>
        </a>
    </div>
</div>

<!-- 主内容区域 -->
<div class="main-content">
    <div class="header">
        <h1>个人资料</h1>
        <div class="user-profile">
            <img th:src="@{/images/default-avatar.jpg}" alt="用户头像">
            <div class="user-info">
                <span class="user-name" th:text="${session.user.nickname ?: session.user.username}">用户名</span>
                <span class="user-role" th:text="${session.user.isSuperAdmin ? '超级管理员' : '普通用户'}">用户角色</span>
            </div>
        </div>
    </div>

    <form th:action="@{/user/profile/update}" method="post" class="profile-card">
        <div class="profile-header">
            <div class="profile-avatar">
                <img th:src="@{/images/default-avatar.jpg}" alt="用户头像">
                <div class="profile-avatar-edit" title="更换头像">
                    <i class="fas fa-camera"></i>
                </div>
            </div>
            <div class="profile-title">
                <h2 th:text="${session.user.nickname ?: session.user.username}">用户名</h2>
                <p th:text="${session.user.isSuperAdmin ? '超级管理员' : '普通用户'}">用户角色</p>
            </div>
        </div>

        <!-- 错误提示 -->
        <div th:if="${error}" class="error-message">
            <i class="fas fa-exclamation-circle"></i>
            <span th:text="${error}"></span>
        </div>

        <!-- 成功提示 -->
        <div th:if="${success}" class="success-message">
            <i class="fas fa-check-circle"></i>
            <span th:text="${success}"></span>
        </div>

        <div class="profile-form">
            <div class="form-group">
                <label for="username">用户账号</label>
                <input type="text" id="username" class="form-control readonly-field"
                       th:value="${session.user.username}" readonly>
            </div>

            <div class="form-group">
                <label for="nickname">昵称</label>
                <input type="text" id="nickname" name="nickname" class="form-control"
                       th:value="${session.user.nickname}" placeholder="请输入昵称">
            </div>

            <div class="form-group">
                <label for="gender">性别</label>
                <select id="gender" name="gender" class="form-control">
                    <option value="">-- 请选择性别 --</option>
                    <option value="male" th:selected="${session.user.gender == 'male'}">男</option>
                    <option value="female" th:selected="${session.user.gender == 'female'}">女</option>
                    <option value="other" th:selected="${session.user.gender == 'other' || session.user.gender == null}">其他</option>
                </select>
            </div>

            <div class="form-group">
                <label for="phoneNumber">手机号码</label>
                <input type="tel" id="phoneNumber" name="phoneNumber" class="form-control"
                       th:value="${session.user.phoneNumber}" placeholder="请输入手机号码">
            </div>

            <div class="form-group">
                <label for="email">电子邮箱</label>
                <input type="email" id="email" name="email" class="form-control"
                       th:value="${session.user.email}" placeholder="请输入电子邮箱">
            </div>

            <div class="form-group">
                <label>账号状态</label>
                <input type="text" class="form-control readonly-field"
                       th:value="${session.user.status == 1 ? '激活' : '禁用'}" readonly>
            </div>

            <!-- 修改企业ID显示 -->
            <div class="form-group">
                <label>所属企业</label>
                <input type="text" class="form-control readonly-field"
                       th:value="${enterpriseMap?.get(session.user.enterpriseId)?.enterpriseName ?: '未绑定企业'}" readonly>
            </div>
        </div>

        <!-- 密码修改区域 -->
        <div class="password-section">
            <h3 class="password-title">
                <i class="fas fa-key"></i> 修改密码
            </h3>
            <div class="profile-form">
                <div class="form-group">
                    <label for="currentPassword">当前密码</label>
                    <input type="password" id="currentPassword" name="currentPassword" class="form-control" placeholder="请输入当前密码">
                </div>

                <div class="form-group">
                    <label for="newPassword">新密码</label>
                    <input type="password" id="newPassword" name="newPassword" class="form-control" placeholder="请输入新密码">
                </div>

                <div class="form-group">
                    <label for="confirmPassword">确认新密码</label>
                    <input type="password" id="confirmPassword" name="confirmPassword" class="form-control" placeholder="请再次输入新密码">
                </div>
            </div>
        </div>

        <div class="form-actions">
            <button type="button" class="btn btn-outline" onclick="window.location.href='/index'">
                <i class="fas fa-arrow-left"></i> 返回
            </button>
            <button type="submit" class="btn btn-primary">
                <i class="fas fa-save"></i> 保存更改
            </button>
        </div>
    </form>
</div>

<script>
    // 设置当前激活菜单项
    document.addEventListener('DOMContentLoaded', function() {
        const menuItems = document.querySelectorAll('.menu-item');
        const currentPath = window.location.pathname;

        menuItems.forEach(item => {
            if (item.getAttribute('href') === currentPath) {
                item.classList.add('active');
            } else {
                item.classList.remove('active');
            }
        });

        // 密码匹配验证
        document.getElementById('confirmPassword').addEventListener('blur', function() {
            const newPassword = document.getElementById('newPassword').value;
            const confirmPassword = this.value;

            if (newPassword && newPassword !== confirmPassword) {
                this.setCustomValidity('两次输入的密码不一致');
            } else {
                this.setCustomValidity('');
            }
        });

        // 头像上传处理
        document.querySelector('.profile-avatar-edit').addEventListener('click', function() {
            const input = document.createElement('input');
            input.type = 'file';
            input.accept = 'image/*';

            input.onchange = function(e) {
                const file = e.target.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(event) {
                        document.querySelector('.profile-avatar img').src = event.target.result;
                        // 这里可以添加AJAX请求上传图片到服务器
                    };
                    reader.readAsDataURL(file);
                }
            };

            input.click();
        });
    });
</script>
</body>
</html>